<?php
	$reldir = "../";
	require_once("../query_includes.php");
	header("Content-Type: text/javascript");
?>

var queries = new Array();

function Query(title, params) {
	this.title	= title;
	this.params	= params;
}

function getQueryByTitle(title) {
	for (var i=0; i<queries.length; i++) {
		if (queries[i].title == title)
			return queries[i];
	}
}

function getParamNameFromDefinition(q, def) {
	for (paramName in q.params) {
		var paramType = q.params[paramName];
		var realParamType = paramType;
		if (paramType & SELECT_MULTIPLE) {
			realParamType = paramType - 1;
		}

		if (compare(realParamType,def)) {
			return paramName;
		}
	}

	return null;
}


<?php

	$queries = Registry::getByRealm("query");

	for ($i=0; $i<sizeof($queries); $i++) {
		$title  = $queries[$i]->getTitle();
		$params = $queries[$i]->getParams();

		echo "queries.push(new Query('".$title."', {";

		$isFirst = 1;
		foreach($params as $paramName=>$paramType) {

			if ($isFirst)
				$isFirst = false;
			else
				echo ", ";

			echo "'".$paramName."':";
			if (is_array($paramType)) {
				echo "new Array(";
				for ($k=0; $k<sizeof($paramType); $k++) {
					if ($k>0)
						echo ",";
					echo "'".$paramType[$k]."'";
				}
				echo ")";
			} else {
				echo $paramType;
			}

		}
		echo "}));\n";
	}

?>